package com.SetDemo.Test;

/*
 * 存储学生对象并遍历，创建集合使用无参构造方法
 * 要求：按照年龄从小到大排序，年龄相同，按照姓名的字母顺序排序
 * */

import java.util.TreeSet;

public class TreeSetDemo03 {
    public static void main(String[] args) {
        TreeSet<Student> treeSet = new TreeSet<Student>();

        Student s1 = new Student("xishi", 29);
        Student s2 = new Student("wangzhuxian", 28);
        Student s3 = new Student("liuyan", 35);
        Student s4 = new Student("yangyuhuan", 32);
        Student s5 = new Student("linqingxia", 32);
        Student s6 = new Student("linqingxia", 32);

        treeSet.add(s1);
        treeSet.add(s2);
        treeSet.add(s3);
        treeSet.add(s4);
        treeSet.add(s5);
        treeSet.add(s6);

        for (Student s : treeSet) {
            System.out.println(s.getName() + "," + s.getAge());
        }

    }
}
